<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class CV extends CI_Controller{
    public function __construct() {
        parent::__construct();
        $this->load->model('Cv_model');
        $this->load->model('Staff_model');
        $this->load->helper('url');
        $this->load->helper('form');
        $this->load->library('form_validation');
        $this->load->library('session');
        $this->load->library('pagination');
    }
    public function loadFormInsertCV()
    {
        $email=$this->session->userdata('email');
        $data['email']=$email;
        $this->load->view('_header',$data);
        $this->load->view('CV/loadFormInsertCV');
        $this->load->view('_footer');
    }
    public function insertCV()
    {
        $email=$this->session->userdata('email');
        $data['email']=$email;
        $FullName=trim($this->security->sanitize_filename($this->input->post('txtFullName')));
        $FirstName=trim($this->security->sanitize_filename($this->input->post('txtFirstName')));
        $LastName=trim($this->security->sanitize_filename($this->input->post('txtLastName')));
        $Day=trim($this->security->sanitize_filename($this->input->post('txtDay')));
        $Month=trim($this->security->sanitize_filename($this->input->post('txtMonth')));
        $Year=trim($this->security->sanitize_filename($this->input->post('txtYear')));
        $DayIssue=trim($this->security->sanitize_filename($this->input->post('txtDayIssue')));
        $MonthIssue=trim($this->security->sanitize_filename($this->input->post('txtMonthIssue')));
        $YearIssue=trim($this->security->sanitize_filename($this->input->post('txtYearIssue')));
        $POB=trim($this->security->sanitize_filename($this->input->post('txtPlaceBirthday')));
        $Marital=trim($this->security->sanitize_filename($this->input->post('txtMaritalStatus')));
        $Gender=trim($this->security->sanitize_filename($this->input->post('txtGender')));
        $IDNumber=trim($this->security->sanitize_filename($this->input->post('txtIDNumber')));
        $POI=trim($this->security->sanitize_filename($this->input->post('txtPOI')));
        $PersonalEmail1=trim($this->security->sanitize_filename($this->input->post('txtPersonalEmail1')));
        $PersonalEmail2=trim($this->security->sanitize_filename($this->input->post('txtPersonalEmail2')));
        $HomePhone=trim($this->security->sanitize_filename($this->input->post('txtHomePhone')));
        $CellPhone=trim($this->security->sanitize_filename($this->input->post('txtCellPhone')));
        $CVSumup=trim($this->security->sanitize_filename($this->input->post('txtCVSUmup')));
        $Foreigners=trim($this->security->sanitize_filename($this->input->post('txtForeigners')));
        $PositionInterview=trim($this->security->sanitize_filename($this->input->post('txtPositionInterview')));
        $DOB=$Day.'/'.$Month.'/'.$Year;
        $DOI=$DayIssue.'/'.$MonthIssue.'/'.$YearIssue;
        $data['FullName']=$FullName;
        $data['FirstName']=$FirstName;
        $data['LastName']=$LastName;
        $data['Day']=$Day;
        $data['Month']=$Month;
        $data['Year']=$Year;
        $data['DayIssue']=$DayIssue;
        $data['MonthIssue']=$MonthIssue;
        $data['YearIssue']=$YearIssue;
        $data['POB']=$POB;
        $data['IDNumber']=$IDNumber;
        $data['Marital']=$Marital;
        $data['Gender']=$Gender;
        $data['POI']=$POI;
        $data['HomePhone']=$HomePhone;
        $data['CellPhone']=$CellPhone;
        $data['PersonalEmail1']=$PersonalEmail1;
        $data['PersonalEmail2']=$PersonalEmail2;
        $data['CVSumup']=$CVSumup;
        $data['Foreigners']=$Foreigners;
        $data['PositionInterview']=$PositionInterview;
        $query=$this->Cv_model->checkIDNumberExist($IDNumber);
        if($query->num_rows()!=0)
        {
            $data['exist_idnumber']="ID Number existed";
            $this->load->view('_header',$data);
            $this->load->view('CV/loadFormInsertCV');
            $this->load->view('_footer');
        }
        else
        {
        $this->Cv_model->addCV($FullName,$FirstName,$LastName,$POB,$Marital,$Gender,$IDNumber,$DOI,$POI,$PersonalEmail1,$PersonalEmail2,$HomePhone,$CellPhone,$CVSumup,$DOB,$Foreigners,$PositionInterview);
        $data['query']=$this->Cv_model->getListCV();
        redirect('interview/loadListCV');
        }
    }
    public function loadCVUpdateForm($CV_ID)
    {
        $email=$this->session->userdata('email');
        $data['email']=$email;
        $query=$this->Cv_model->getCVByCVID($CV_ID);
        $data['CV_ID']=$CV_ID;
        foreach ($query->result() as $row)
        {
        $data['FullName']=$row->FullName;
        $data['FirstName']=$row->FirstName;
        $data['LastName']=$row->LastName;
        $data['Day']=substr($row->DOB,0,2);
        $data['Month']=substr($row->DOB,3,2);
        $data['Year']=substr($row->DOB,6,4);
        $data['DayIssue']=substr($row->DOI,0,2);
        $data['MonthIssue']=substr($row->DOI,3,2);
        $data['YearIssue']=substr($row->DOI,6,4);
        $data['POB']=$row->POB;
        $data['IDNumber']=$row->ID_Number;
        $data['Marital']=$row->MaristalStatus;
        $data['Gender']=$row->Gender;
        $data['POI']=$row->POI;
        $data['HomePhone']=$row->HomePhone;
        $data['CellPhone']=$row->CellPhone;
        $data['PersonalEmail1']=$row->PersonalEmail1;
        $data['PersonalEmail2']=$row->PersonalEmail2;
        $data['CVSumup']=$row->CV_Sumup;
        $data['Foreigners']=$row->Foreigners;
        $data['PositionInterview']=$row->PositionInterview;
        $this->load->view('_header',$data);
        $this->load->view('CV/loadFormUpdateCV');
        $this->load->view('_footer');
        }
    }
    public function viewCV($CV_ID)
    {
        $email=$this->session->userdata('email');
        $data['email']=$email;
        $query=$this->Cv_model->getCVByCVID($CV_ID);
        $data['CV_ID']=$CV_ID;
        foreach ($query->result() as $row)
        {
        $data['FullName']=$row->FullName;
        $data['FirstName']=$row->FirstName;
        $data['LastName']=$row->LastName;
        $data['DOB']=$row->DOB;
        $data['Day']=substr($row->DOB,0,2);
        $data['Month']=substr($row->DOB,3,2);
        $data['Year']=substr($row->DOB,6,4);
        $data['DOI']=$row->DOI;
        $data['DayIssue']=substr($row->DOI,0,2);
        $data['MonthIssue']=substr($row->DOI,3,2);
        $data['YearIssue']=substr($row->DOI,6,4);
        $data['POB']=$row->POB;
        $data['IDNumber']=$row->ID_Number;
        $data['Marital']=$row->MaristalStatus;
        $data['Gender']=$row->Gender;
        $data['POI']=$row->POI;
        $data['HomePhone']=$row->HomePhone;
        $data['CellPhone']=$row->CellPhone;
        $data['PersonalEmail1']=$row->PersonalEmail1;
        $data['PersonalEmail2']=$row->PersonalEmail2;
        $data['CVSumup']=$row->CV_Sumup;
        $data['Foreigners']=$row->Foreigners;
        $data['PositionInterview']=$row->PositionInterview;
        $this->load->view('_header',$data);
        $this->load->view('CV/viewCV');
        $this->load->view('_footer');
        }
    }
    public function updateCV()
    {
        $email=$this->session->userdata('email');
        $data['email']=$email;
        $CV_ID=trim($this->security->sanitize_filename($this->input->post('txtCVID')));
        $FullName=trim($this->security->sanitize_filename($this->input->post('txtFullName')));
        $FirstName=trim($this->security->sanitize_filename($this->input->post('txtFirstName')));
        $LastName=trim($this->security->sanitize_filename($this->input->post('txtLastName')));
        $Day=trim($this->security->sanitize_filename($this->input->post('txtDay')));
        $Month=trim($this->security->sanitize_filename($this->input->post('txtMonth')));
        $Year=trim($this->security->sanitize_filename($this->input->post('txtYear')));
        $DayIssue=trim($this->security->sanitize_filename($this->input->post('txtDayIssue')));
        $MonthIssue=trim($this->security->sanitize_filename($this->input->post('txtMonthIssue')));
        $YearIssue=trim($this->security->sanitize_filename($this->input->post('txtYearIssue')));
        $POB=trim($this->security->sanitize_filename($this->input->post('txtPlaceBirthday')));
        $Marital=trim($this->security->sanitize_filename($this->input->post('txtMaritalStatus')));
        $Gender=trim($this->security->sanitize_filename($this->input->post('txtGender')));
        $IDNumber=trim($this->security->sanitize_filename($this->input->post('txtIDNumber')));
        $POI=trim($this->security->sanitize_filename($this->input->post('txtPOI')));
        $PersonalEmail1=trim($this->security->sanitize_filename($this->input->post('txtPersonalEmail1')));
        $PersonalEmail2=trim($this->security->sanitize_filename($this->input->post('txtPersonalEmail2')));
        $HomePhone=trim($this->security->sanitize_filename($this->input->post('txtHomePhone')));
        $CellPhone=trim($this->security->sanitize_filename($this->input->post('txtCellPhone')));
        $CVSumup=trim($this->security->sanitize_filename($this->input->post('txtCVSUmup')));
        $Foreigners=trim($this->security->sanitize_filename($this->input->post('txtForeigners')));
        $DOB=$Day.'/'.$Month.'/'.$Year;
        $DOI=$DayIssue.'/'.$MonthIssue.'/'.$YearIssue;
        $PositionInterview=trim($this->security->sanitize_filename($this->input->post('txtPositionInterview')));
        /*$query=$this->Cv_model->checkIDNumberExist($IDNumber);
        if($query->num_rows()!=0)
        {
            $data['exist_idnumber']="ID Number existed";
            $this->load->view('_header',$data);
            $this->load->view('CV/loadFormUpdateCV/'.$CV_ID);
            $this->load->view('_footer');
        }
        else
        {*/
        $this->Cv_model->updateCV($CV_ID,$FullName,$FirstName,$LastName,$POB,$Marital,$Gender,$IDNumber,$DOI,$POI,$PersonalEmail1,$PersonalEmail2,$HomePhone,$CellPhone,$CVSumup,$DOB,$Foreigners,$PositionInterview);
        $data['query']=$this->Cv_model->getListCV();
        redirect('interview/loadListCV');
        //}
    }
    public function viewExperienceCV($CV_ID)
    {
        $email=$this->session->userdata('email');
        $data['email']=$email;
        $data['CV_ID']=$CV_ID;
        $query=$this->Cv_model->getFullNameByCVID($CV_ID);
        foreach ($query->result() as $row)
        {
            $data['FullName']=$row->FullName;
        }
        $data['query']=$this->Cv_model->getListExperienceCV($CV_ID);
        $this->load->view('_header',$data);
        $this->load->view('CV/listExperienceCV');
        $this->load->view('_footer');
    }
    public function loadFormInsertExperience($CV_ID)
    {
        $email=$this->session->userdata('email');
        $data['email']=$email;
        $data['CV_ID']=$CV_ID;
        $query=$this->Cv_model->getFullNameByCVID($CV_ID);
        foreach ($query->result() as $row)
        {
            $data['FullName']=$row->FullName;
        }
        $this->load->view('_header',$data);
        $this->load->view('CV/loadFormInsertExperienceCV');
        $this->load->view('_footer');
    }
      public function insertExperienceCV()
        {
        $email=$this->session->userdata('email');
        $data['email']=$email;
        $CV_ID=trim($this->security->sanitize_filename($this->input->post('txtCVID')));
        $data['CV_ID']=$CV_ID;
        $Education=trim($this->security->sanitize_filename($this->input->post('txtEducation')));
        $PreviousPosition=trim($this->security->sanitize_filename($this->input->post('txtPreviousPosition')));
        $Company=trim($this->security->sanitize_filename($this->input->post('txtCompany')));
        $Industry=trim($this->security->sanitize_filename($this->input->post('txtIndustry')));
        $Year=trim($this->security->sanitize_filename($this->input->post('txtYear')));
        $query=$this->Cv_model->checkExperienceCV($CV_ID,$Education,$PreviousPosition,$Company,$Industry,$Year);
        $query1=$this->Cv_model->getFullNameByCVID($CV_ID);
        foreach ($query1->result() as $row1)
        {
            $data['FullName']=$row1->FullName;
        }
        if($query->num_rows()!=0)
        {
            $data['Education']=$Education;
            $data['PreviousPosition']=$PreviousPosition;
            $data['Company']=$Company;
            $data['Industry']=$Industry;
            $data['Year']=$Year;
            $data['experience_exist']="Experience was added";
            $this->load->view('_header',$data);
            $this->load->view('CV/loadFormInsertExperienceCV');
            $this->load->view('_footer');
        }
        else
        {
            $this->Cv_model->insertExperienceCV($CV_ID,$Education,$PreviousPosition,$Company,$Industry,$Year);
            redirect('CV/viewExperienceCV/'.$CV_ID);
        }
    }
    public function loadExperienceUpdateForm($EC_ID)
    {
        $email=$this->session->userdata('email');
        $data['email']=$email;
        $EC=  explode("-", $EC_ID);
        $Experience_ID=$EC[0];
        $CV_ID=$EC[1];
        $data['Experience_ID']=$Experience_ID;
        $data['CV_ID']=$CV_ID;
        $query1=$this->Cv_model->getFullNameByCVID($CV_ID);
        foreach ($query1->result() as $row1)
        {
            $data['FullName']=$row1->FullName;
        }
        $query=$this->Staff_model->getExperienceByExperienceID($Experience_ID);
        foreach ($query->result() as $row)
        {
            $data['Education']=$row->Education;
            $data['PreviousPosition']=$row->PreviousPosition;
            $data['Company']=$row->Company;
            $data['Industry']=$row->Industry;
            $data['Year']=$row->Year;
        }
        $this->load->view('_header',$data);
        $this->load->view('CV/loadExperienceUpdateForm');
        $this->load->view('_footer');
    }
    public function updateExperienceCV()
    {
        $email=$this->session->userdata('email');
        $data['email']=$email;
        $CV_ID=trim($this->security->sanitize_filename($this->input->post('txtCVID')));
        $data['CV_ID']=$CV_ID;
        $Experience_ID=trim($this->security->sanitize_filename($this->input->post('txtExperienceID')));
        $data['Experience_ID']=$Experience_ID;
        $Education=trim($this->security->sanitize_filename($this->input->post('txtEducation')));
        $PreviousPosition=trim($this->security->sanitize_filename($this->input->post('txtPreviousPosition')));
        $Company=trim($this->security->sanitize_filename($this->input->post('txtCompany')));
        $Industry=trim($this->security->sanitize_filename($this->input->post('txtIndustry')));
        $Year=trim($this->security->sanitize_filename($this->input->post('txtYear')));
        //$query=$this->Staff_model->checkExperienceStaff($Staff_ID,$PreviousPosition,$Company,$Industry,$Year);
        $query1=$this->Cv_model->getFullNameByCVID($CV_ID);
        foreach ($query1->result() as $row1)
        {
            $data['FullName']=$row1->FullName;
        }
        
            $this->Staff_model->updateExperienceStaff($Experience_ID,$Education,$PreviousPosition,$Company,$Industry,$Year);
            redirect('CV/viewExperienceCV/'.$CV_ID);
    }
    public function deleteExperienceCV($EC_ID)
    {
        $email=$this->session->userdata('email');
        $data['email']=$email;
        $EC=  explode("-", $EC_ID);
        $Experience_ID=$EC[0];
        $CV_ID=$EC[1];
        $data['Experience_ID']=$Experience_ID;
        $data['CV_ID']=$CV_ID;
        $this->Staff_model->deleteExperienceStaff($Experience_ID);
        redirect('CV/viewExperienceCV/'.$CV_ID);
        
    }
}
?>
